package net.kazed.nextaction.task;

import java.util.regex.Pattern;

import net.kazed.nextaction.database.TaskAttachment;
import net.kazed.nextaction.database.TaskAttachmentList;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.text.util.Linkify;
import android.widget.TextView;
import android.widget.Toast;

public class ContactAttachmentType extends AttachmentType{
    
    /**
     * @param labelResource Resource of label string.
     * @param requestCode Unique code for request.
     */
    public ContactAttachmentType(int labelResource, int requestCode) {
        super(labelResource, requestCode);
    }

    /**
     * @return Intent for attachment type.
     */
    public Intent getIntent() {
        Intent intent = new Intent(Intent.ACTION_PICK, Uri.parse("content://contacts/people"));
        return intent;
    }

    @Override
    public boolean isIntentTargetAvailable(PackageManager packageManager) {
        return true;
    }

    @Override
    public void addAttachment(Context context, ContentResolver contentResolver, Intent data, TaskAttachmentList attachmentList) {
        Toast.makeText(context, "contact: " + data.getData(), Toast.LENGTH_LONG).show();
        attachmentList.add(new TaskAttachment(attachmentList.getTask().getId(), "contact", data.getDataString()));
    }
    
    @Override
    public String getAttachmentLink(Context context, Intent data) {
        return data.getDataString();
    }

    @Override
    public void addLinks(TextView view) {
        Pattern contactMatcher = Pattern.compile("\\bcontent\\://contacts/people/[0-9]+\\b");
        String contactURL = "";
        Linkify.addLinks(view, contactMatcher, contactURL);
    }

}
